<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页</title>
    <link rel="stylesheet" href="./login.css">
</head>

<body>
    <div class="login-box">

        <div class="title">注册</div>
        <div class="form">
            <div class="line">
                <input type="text" placeholder="输入用户名">
            </div>
            <div class="line">
                <input type="password" placeholder="输入密码">
            </div>
            <div class="line">
                <input type="password" placeholder="确认密码">
            </div>
            <div class="line">
                <input type="text" placeholder="输入邮箱">
            </div>
            <div class="line">
                <input type="text" placeholder="输入姓名">
            </div>
            <div class="line">
                <a href="./login.html">已有账号,去登陆</a>
            </div>
            <div class="line btn-box">
                <button>注册</button>
            </div>
        </div>
    </div>
</body>
<script src="./axios.min.js"></script>
</html>
<script>
    var inputs = document.querySelectorAll('input');
    var registerBtn = document.querySelector('button');

    registerBtn.onclick = function () {
        if (inputs[0].value &&
            inputs[1].value &&
            inputs[2].value &&
            inputs[3].value &&
            inputs[4].value
        ) {
            if (/^1[3-9]\d{9}$/.test(inputs[0].value) &&
                inputs[1].value == inputs[2].value
            ) {
                axios.post('/user/register', {
                    phone: inputs[0].value,
                    pass: inputs[2].value,
                    email: inputs[3].value,
                    name:inputs[4].value
                }).then((res) => {
                    console.log(res.data);
                    location.href = './login.html'
                })
            } else if (/^1[3-9]\d{9}$/.test(inputs[0].value) == false) {
                alert('手机号格式不正确!');
            } else {
                alert('两次密码不一致!');
            }
        } else {
            alert('注册信息不完整!');
        }
    }
</script>